package com.chechi.server.service;

import com.chechi.server.util.JerseyUtils;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.JerseyClient;
import org.glassfish.jersey.client.JerseyWebTarget;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;

/**
 * Created by Nemo on 2017/6/10.
 */
public class JerseyTest {
    public void jerseyTest(){

        HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder()
                .nonPreemptive()
                .credentials("nemo", "1234")
                .build();

        ClientConfig clientConfig = new ClientConfig();
        clientConfig.register(feature);

        JerseyClient CLIENT = JerseyUtils.getJerseyClient(false,clientConfig);

        JerseyWebTarget rabbit = CLIENT.target("http://localhost:15672/api/{api}").resolveTemplate("api","overview");
        //resolveTemplate添加path param
        //注意构造器模式和getter/setter模式，构造器模式可以一串调用完，返回的是对象，创建之后再修改需要
        //rabbit = rabbit.resolveTemplate("api","overview")


        Invocation.Builder inbuilder = rabbit.request();
        Response response = inbuilder.get(Response.class);
        String rab = response.readEntity(String.class);
        System.out.println(rab);
    }

    public static void main(String[] args) {
        JerseyTest jerseyTest = new JerseyTest();
        jerseyTest.jerseyTest();
    }
}
